/**
 * 修改css全局变量
 */
import { nextTick } from "vue";
import cssProperty from "./cssVariable";
import {globalColor } from '@/store/pinia';
export const defaultCss = () => {
    Object.keys(cssProperty).forEach((key) => {
        document.documentElement.style.setProperty(key, olorRgb(cssProperty[key]));
    });
};
export const changeCss = (color) => {
    const rbgColor = olorRgb(color);
    const rbgaColor01 = rgb2rbga(rbgColor, 0.1)
    const rbgaColor02 = rgb2rbga(rbgColor, 0.2)
    const rbgaColor03 = rgb2rbga(rbgColor, 0.3)
    const rbgaColor05 = rgb2rbga(rbgColor,0.5)
    const rbgaColor07 = rgb2rbga(rbgColor,0.7)
    globalColor().updateColorObj({ '--isActive-color': color, '--isActive-color-01': rbgaColor01, '--isActive-color-03': rbgaColor03, '--isActive-color-05': rbgaColor05, '--isActive-color-07': rbgaColor07 })
    setTimeout(() => {
        document.documentElement.style.setProperty('--isActive-color', color);
        document.documentElement.style.setProperty('--isActive-color-01', rbgaColor01);
        document.documentElement.style.setProperty('--isActive-color-02', rbgaColor02);
        document.documentElement.style.setProperty('--isActive-color-03', rbgaColor03);
        document.documentElement.style.setProperty('--isActive-color-05', rbgaColor05);
        document.documentElement.style.setProperty('--isActive-color-07', rbgaColor07);
    }, 50);
};
/* 16进制颜色转rgb */
export const olorRgb = (color) => {
    const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
    let sColor = color.toLowerCase();
    if (sColor && reg.test(sColor)) {
        if (sColor.length === 4) {
            let sColorNew = "#";
            for (let i = 1; i < 4; i += 1) {
                sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
            }
            sColor = sColorNew;
        }
        //处理六位的颜色值
        let sColorChange = [];
        for (let i = 1; i < 7; i += 2) {
            sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
        }
        return "rgba(" + sColorChange.join(",") + ")";
    } else {
        return sColor;
    }
};
/* rgb转rgba */
export const rgb2rbga = (color,number) => {
    const rgb = color.split(')')[0]
    return color.split(')')[0] + ',' + number.toString() + ')'
}
